package com.touchdrive;

import java.io.*;
import java.net.*;

import android.util.Log;

public class NetConnect {
	String ipAddr;
	int port;
	Socket sock;
	DataOutputStream output;
	
	public void connect(){
		try{
			sock = new Socket(ipAddr, port);
			output=new DataOutputStream(sock.getOutputStream());
		} catch (UnknownHostException error){
			Log.e("ERROR", error.toString());
		} catch (IOException error1){
			Log.e("ERROR", error1.toString());
		}
	}

	public void send(String data){
		if (sock.isConnected()){
			try {
				output.writeUTF(data);
			} catch (IOException error){
				Log.e("ERROR", error.toString());				
			}
			
		}
	}

	public void close(){
		if (sock.isConnected()){
			try {
				sock.close();
			} catch (IOException error){
				Log.e("ERROR", error.toString());				
			}
			
		}
	}
}
